<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
        1. 在业务中一般用于在条件满足时执行（异步）。
        2. resolve(参数)传递给then((参数)=>{})回调函数的参数
      */
      const p = new Promise(function (resolve, reject) {
        const age = 10;
        if (age < 0) {
          reject(new Error("年龄范围错误"));
        } else {
          resolve("hello"); //异步运行
        }
        console.log("...");
      });
      p.then((data) => {
        console.log("then", data);
      }).catch((e) => {
        console.log(e.message);
      });
    </script>
  </body>
</html>
